﻿@page "/range-selector/range-navigator"
@using Syncfusion.Blazor.Charts
@using Syncfusion.Blazor
@using Newtonsoft.Json
@inject NavigationManager NavigationManager
@inherits SampleBaseComponent;

<SampleDescription>
    <p>This sample visualizes the bitcoin price range with area series in the range navigator. Selected range values are enhanced with tooltip.</p>
</SampleDescription>
<ActionDescription>
    <p>
        In this example, you can see how to render and configure the Range Navigator.
        <code>AreaSeries</code> is used to represent selected data value.
        <code>Tooltip</code> is used to represent selected data value. You can also use <code>SelectedRegionColor</code> and <code>UnselectedRegionColor</code> properties to customize selected and unselected area in range navigator.
    </p>
</ActionDescription>

@if (DefaultData == null)
{
    <div class="stockchartloader"></div>
}
else
{
    <div class="control-section" align="center">
        <h4 style="font-family: Segoe UI;font-weight: 500; font-style:normal; font-size:15px;" align="center">Bitcoin (USD) Price Range</h4>
        <div>
            <SfRangeNavigator Value="@Value" ValueType="Syncfusion.Blazor.Charts.RangeValueType.DateTime" LabelFormat="MMM-yy">
                <RangeNavigatorStyleSettings UnselectedRegionColor="transparent"></RangeNavigatorStyleSettings>
                <RangeNavigatorRangeTooltipSettings Enable="true" DisplayMode="TooltipDisplayMode.Always" Format="MM/dd/yyyy"></RangeNavigatorRangeTooltipSettings>
                <RangeNavigatorSeriesCollection>
                    <RangeNavigatorSeries Fill="@FillColor" DataSource="@DefaultData" XName="x" Type="RangeNavigatorType.Area" YName="y" Width="2"></RangeNavigatorSeries>
                </RangeNavigatorSeriesCollection>
                <RangeNavigatorEvents Loaded="BeforeRender" />
            </SfRangeNavigator>
        </div>
    </div>

}

@code{
    private ChartData[] DefaultData;
    string FillColor;
    string valueUrl = "url";
    protected override async Task OnInitializedAsync()
    {
        await Task.Run(() =>
        {
            DefaultData = JsonConvert.DeserializeObject<ChartData[]>(System.IO.File.ReadAllText("./wwwroot/data/range-navigator/default-data.json"));
        });

        CurrentUri = NavigationManager.Uri;
        if (CurrentUri.IndexOf("material") > -1)
        {

            FillColor = String.Concat(valueUrl, "(#material-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("fabric") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#fabric-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("bootstrap4") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#bootstrap4-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("bootstrap") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#bootstrap-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("highcontrast") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#highcontrast-gradient-chart)");
        }
        else if (CurrentUri.IndexOf("tailwind") > -1)
        {
            FillColor = String.Concat(valueUrl, "(#tailwind-gradient-chart)");
        }
        else
        {
            FillColor = String.Concat(valueUrl, "(#bootstrap4-gradient-chart)");
        }
    }
    public class ChartData
    {
        public DateTime x { get; set; }
        public double y { get; set; }
    }
    private object[] Value = new object[] { new DateTime(2017, 09, 01), new DateTime(2018, 02, 01) };

    string CurrentUri;
    void BeforeRender(RangeLoadedEventArgs Args)
    {
        CurrentUri = NavigationManager.Uri;
        if (CurrentUri.IndexOf("material") > -1)
        {
            Args.Theme = Theme.Material;
        }
        else if (CurrentUri.IndexOf("fabric") > -1)
        {
            Args.Theme = Theme.Fabric;
        }
        else if (CurrentUri.IndexOf("bootstrap") > -1)
        {
            Args.Theme = Theme.Bootstrap;
        }
        else if (CurrentUri.IndexOf("highcontrast") > -1)
        {
            Args.Theme = Theme.HighContrast;
        }
        else if (CurrentUri.IndexOf("tailwind") > -1)
        {
            Args.Theme = Theme.Tailwind;
        }
        else
        {
            Args.Theme = Theme.Bootstrap4;
        }
    }
}
<style>
    #control-container {
        padding: 0px !important;
    }

    #container {
        transform: translate(0, 25%);
    }

    #material-gradient-chart stop {
        stop-color: #00bdae;
    }

    #fabric-gradient-chart stop {
        stop-color: #4472c4;
    }

    #bootstrap-gradient-chart stop {
        stop-color: #a16ee5;
    }

    #bootstrap4-gradient-chart stop {
        stop-color: #a16ee5;
    }

    #highcontrast-gradient-chart stop {
        stop-color: #79ECE4;
    }

    #tailwind-gradient-chart stop {
        stop-color: #4F46E5;
    }

    .chart-gradient stop[offset="0"] {
        stop-opacity: 0.9;
    }

    .chart-gradient stop[offset="1"] {
        stop-opacity: 0.3;
    }
</style>
<svg style="height: 0">
    <defs>
        <linearGradient id="material-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="fabric-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="bootstrap-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="bootstrap4-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="highcontrast-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
        <linearGradient id="tailwind-gradient-chart" style="opacity: 0.75" class="chart-gradient" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0"></stop>
            <stop offset="1"></stop>
        </linearGradient>
    </defs>
</svg>